package org.lanqiao.tjut.control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.ScoreBean;
import org.lanqiao.tjut.bean.StudentBean;
import org.lanqiao.tjut.myUtils.MyUtils;
import org.lanqiao.tjut.service.ServiceFactory;

public class SelectClassS extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 创建成绩表实例对象
		ScoreBean scorebean = (ScoreBean) MyUtils.getNewInsdence(ScoreBean.class);
		// 获取学生选课的课程名
		String secClassName = request.getParameter("classname");
		scorebean.setClassname(secClassName);
		// 获取学生选课的教师名
		String secTeaName = request.getParameter("teaname");
		scorebean.setTeaname(secTeaName);
		StudentBean stuBean = (StudentBean) request.getSession().getAttribute("LoginedUserS");

		scorebean.setStuname(stuBean.getStuname());
		// 将学生选课添加进成绩表中
		int i = ServiceFactory.getSelectClassManagerServiceInstance().SavaClassS(scorebean);
		if (i > 0) {
			MyUtils.logger_rootLogger.info("学生" + scorebean.getStuname() + "选择" + scorebean.getTeaname() + "老师的课程["
					+ scorebean.getClassname() + "]成功！");

			// List<ScoreBean> lst =
			// ServiceFactory.getSelectClassManagerServiceInstance().getStuAllClassInfo(scorebean);
			// 将需要显示的结果(查询的所有用户信息)存入session缓存中
			// request.getSession().setAttribute("lst", lst);

			// 跳转到相应页面进行显示
			request.getRequestDispatcher("QueryAllTeaClass").forward(request, response);
		} else {
			request.getSession().setAttribute("pageErrorInfo", "课程信息加载失败！");
			response.sendRedirect("Logined/Error.jsp");
		}
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
